﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Win32Proxy.Api;
using Win32Proxy.Enums;

namespace WinCapturer
{
    public class PrintCaptureHelper : AbsCaptureHelper
    {
        protected override bool CommonInit()
        {
            HScrDc = User32.GetWindowDC(HWnd);
            HBitmap = GDI32.CreateCompatibleBitmap(HScrDc, WinClientRect.Width, WinClientRect.Height);
            HMemDc = GDI32.CreateCompatibleDC(HScrDc);
            HOldBitmap = GDI32.SelectObject(HMemDc, HBitmap);
            return true;
        }

        protected override IntPtr DoCapture()
        {
            var ret = User32.PrintWindow(HWnd, HMemDc,
                (uint)PrintWindowMode.PW_CLIENTONLY |
                (uint)PrintWindowMode.PW_RENDERFULLCONTENT);
            return ret ? HBitmap : IntPtr.Zero;
        }

        protected override bool DoCapture(out IntPtr bitsPtr)
        {
            bitsPtr = HBitmap;
            var ret = User32.PrintWindow(HWnd, HMemDc,
                (uint)PrintWindowMode.PW_CLIENTONLY |
                (uint)PrintWindowMode.PW_RENDERFULLCONTENT);
            return ret;
        }
    }
}
